Customising

All the customisation information is in a self-contained script - custom.js which can be found in the resources folder. Having this information in a script on its own means that future upgrades can be easily integrated, without you having to re-enter your design from scratch. Another advantage is that custom scripts are interchangeable with other people who use these menus.

There are quite a few variables ... split into Global style definitions and Menu and link definitions:

Global style definitions

menuALIGN// alignment

global alignment in the browser window, the choices are "left", "center" or "right".

There is also a fourth option - menuALIGN="free". If you set this, then the horizontal navbar will be broken up into component cells, each of which is positioned individually. This allows you to build other orientations, such as a vertical navbar, a vertical and horiztonal navbar, or a more esoteric setup with menu triggers dotted throughout the page. For more information about this, please read the tutorial Using free alignment

The script includes a resize/reload trap at all settings, so the nav gets repositioned if the browser window is resized. This can be disabled if you want, using the allowRESIZE variable.

absLEFT// absolute left or right position (if menu is left or right aligned)

the distance in pixels from the left or right edge of the window, depending on how you have it aligned. If you choose center alignment this figure will have no effect; if you choose free alignment it will be from the left edge.

This variable sets an absolute position, however if you use relative positioning then whatever you define here is ignored.

absTOP// absolute top position

the distance in pixels from the top of the browser window.

This variable sets an absolute position, however if you use relative positioning then whatever you define here is ignored.

staticMENU// static positioning mode (ie5,ie6 and ns4 only)

the options are true or false. If true, the nav will remain at a static distance from the top of the window as you scroll down the page, the distance defined by absTOP.

This option is only available in explorer 5 and 6 for windows and netscape 4 for windows and mac; it's too slow in other browsers.


stretchMENU// show empty cells

the choices are true or false. If true it will fill the empty space to the left and/or right of the nav with a blank cell the same as the main nav background color (see mCOLOR), so the navbar appears to stretch across the whole screen.

The width is adjusted to allow for the presence or lack of scrollbars in mozilla, but in opera there is no combination of properties to detect this difference (as far as I can discover), so in this browsers if all the page content is above the fold, and the scrollbar disappears, you will get a 16px gap to the right.

This option is not available if menuALIGN="free"

showBORDERS// show empty cell borders

the choices are true or false. If true it adds borders to the blank cells (if borders are used - see bSIZE and bCOLOR). Note that the border color is actually a solid background layer with the main layer superimposed. This means that if you set showBORDERS=true and stretchMENU=false you will get a solid block of color in the empty spaces, which is the same color or image that you specified for the borders

This option is not available if menuALIGN="free"

baseHREF// base path

This is currently set to "resources/", and if your pages are all in a single folder, then you don't need to change this. However if your site spans multiple folders in a complex heirarchy you will need to have a centralised location for all the component scripts and images. You can specify the path to the main scripts on a per-page basis with the script tags, eg:

    <script language="javascript" src="../../resources/sniffer.js"></script>

But the scripts themselves need an absolute path, so baseHREF is used to define this. I recommend you design and customise the layout from a single template that's in the parent directory of the resources folder (like in the zip file), and then change the baseHREF when you're ready to go live. Either of two methods can be used, an absolute path, eg:

    var baseHREF = "http://www.domain.com/mysite/resources/";

or a path relative to the base directory, eg:

    var baseHREF = "/mysite/resources/";

The first method is slightly slower, but will work when you view the pages locally, although it will still be drawing its scripts and images from your live directory. The second method is more efficient but will break locally ... unless your local file system happens to mirror that of your web server (highly unlikely). However it breaks in a really nice way - no errors are generated, you simply don't see a navbar.

An alternative, if you want to be able to surf your site locally exactly as live, is to use an absolute local path when you build or edit your site, and then change it to an absolute url when you publish. eg:

    var baseHREF = "C:/Cake/Internet/WebPages/dropdown/resources/";

    for testing, could become

    var baseHREF = "/dropdown/resources/";

    when it goes live

Note that even though local addresses in Windows are split with a backslash \ (or a colon : in MacOS) you will need to change these to forward slashes / for the benefit of the script. This will only function in Internet Explorer, because other browsers use different syntax for local addresses.

However, and this is very groovy, you could add a self-referencing function, which checks the document url to discover if you're looking at a local or live copy, and then adjusts baseHREF to suit. This stress-reducing idea comes courtesy of Alan Lam - paste this whole code fragment into your custom.js, replacing the current baseHREF definition, and then changing the paths to suit your situation:

    var baseHREF = "/dropdown/resources/";
    var thisLoc = document.location.href;
    if ((thisLoc.indexOf("http://")==-1)&&(thisLoc.indexOf("wysiwyg://")==-1)) {
       baseHREF = "C:/Cake/Internet/WebPages/dropdown/resources/";
       if (op5||op6) { baseHREF = "file://localhost/C:/Cake/Internet/WebPages/dropdown/resources/"; }
       if (ns4||ns6||mz7) { baseHREF = "file:///C|/Cake/Internet/WebPages/dropdown/resources/"; }
       }


zORDER// base z-order of nav structure (not ns4)

the navbar and menus take up 13 levels of z-index, which by default is 1000-1013. This variable allows you to specify the base z-index, bringing the navbar above (or below) other page content if necessary.

This is not supported in Netscape 4's script, but the issue is unlikely to arise - z-ordering with netscape layers is most easily acheived by adding elements in heirarchical order, from the base level upwards; having the menu script include at the very end of the page puts the nav layers on top, unless you have other layers on your page which are specifically defined as absolute top layers. If so you may need to redefine their heirarchy.

mCOLOR// main nav cell color

the background color of top link cells. Specify a hex color value or color name. If you set this value as mCOLOR="" you will get background transparency

rCOLOR// main nav cell rollover color

the rollover color of top link cells, with the same options as mCOLOR. Set var rCOLOR="" to disable the rollover.

bSIZE// main nav border size

the thickness of the top nav border in pixels

bCOLOR// main nav border color

the top nav border color, with the same options as mCOLOR. Note that the border is actually a solid background layer with the main layer superimposed. This means that if you set mCOLOR to be transparent then the border color will appear as a solid layer below, even if bSIZE is set to 0. Set var bCOLOR = "" to make this layer transparent.

aLINK// main nav link color

as a hex color value or color name

aHOVER// main nav link hover-color (dual purpose)

as a hex color value or color name, this is activated when your mouse moves into the link cell. Depending on whether you're using a rollover, it can function as a link hover color, like the original skin demo, or as a rollover color change, allowing for high-contrast rollovers such as in the retrotech demo

Set this to aHOVER = "" to disable it.

aDEC// main nav link decoration

the choices are "none", "underline", "overline" or "line-through"

fFONT// main nav font face

if you use unusual fonts it's wise to specify alternatives, eg:

    var fFONT = "tempus sans itc,garamond,times new roman,serif";

If you use cursive fonts such as comic sans ms, you may need to do some tweaking with the vertical padding to get it to look okay, because cursive fonts are bigger than a specified pixel size. Monotype fonts (such as Courier in the "Retrotech" demo) are unpredictable, since they are sized differently in different browsers. You should always end a choice of fonts with one which is universally available - sans-serif or serif. This is essential if you want your final menus to be readable by all; for example, in ie4 sp2 on a new installation of Windows 95, the default cursive font is wingdings!

fSIZE// main nav font size (pixels)

this value is adjusted for windows/ns4 and mac/opera 5, which render text 1 unit smaller than the same font size in other browsers.

The size is fixed absolutely in ie and ns4, but can be changed in netscape 6 and mozilla, potentially screwing up the whole layout. I suggest calm fatalism. Opera 5 has a "zoom" feature which increases the magnification of the whole page in proportion, so relative positions and sizes should remain intact.

fWEIGHT// main nav font weight

the choices are "normal" or "bold". I've heard of another CSS option, "medium-bold", but never been able to see any difference between that and bold. If you define fWEIGHT = "" it will default to "normal"

tINDENT// main nav text indent (if text is left or right aligned)

specify the text indentation from the left or right edge of the containing cell, depending on which alignment you choose (see Menus and link definitions). If you choose center alignment for a given link, then this variable will make no difference to it

vPADDING// main nav vertical cell padding

adds vertical cell padding to the top nav bar, giving control of the overall height

vtOFFSET// main nav vertical text offset (+/- pixels from middle)

by default, links will be vertically-aligned in the middle of their containing cells. Use this variable to globally shift the main nav text down (+) or up (-) the specified number of pixels.

Note that text cannot be vertically offset to the extent that it's outside its containing cell, or it will be clipped in Netscape 4. This property should be used carefully, with enough vertical cell padding to compensate.

keepLIT// keep rollover color when browsing menu

the choices are true or false. If true then rCOLOR will remain when your mouse leaves the top nav and browses the submenu, and will rollout when the menu closes

vOFFSET// shift the submenus vertically

by default, each submenu will be immediately underneath the top navbar and start at the edge of its parent link cell (not overlapping the borders). Use this value to shift the entire submenu structure down (+) or up (-) the specified number of pixels. You can also offset each submenu individually, using the submenu properties

hOFFSET// shift the submenus horizontally

use this value to shift the submenu structure right (+) or left (-) the specified number of pixels. Menus which open from the right will be offset in the opposite direction. You can also offset each submenu individually, using the submenu properties

The submenu style variables work the same way as those for the top links, and are global to all menus.

smCOLOR// submenu cell color See mCOLOR

srCOLOR// submenu cell rollover color See rCOLOR

sbSIZE// submenu border size See bSIZE

sbCOLOR// submenu border color See bCOLOR

saLINK// submenu link color See aLINK

saHOVER// submenu link hover-color (dual purpose) See aHOVER

saDEC// submenu link decoration See aDEC

sfFONT// submenu font face See fFONT

sfSIZE// submenu font size (pixels) See fSIZE

sfWEIGHT// submenu font weight See fWEIGHT

stINDENT// submenu text indent (if text is left or right aligned) See tINDENT

svPADDING// submenu vertical cell padding See vPADDING

svtOFFSET// submenu vertical text offset (+/- pixels from middle) See vtOFFSET

shSIZE// menu drop shadow size

you can create a dropshadow effect under the menus. Use this value to define the offset to the right and down from each menu, in pixels. Note that the dropshadow is a solid background layer with the main layer superimposed. So if you set smCOLOR and sbCOLOR to both be transparent, then the dropshadow will appear as a solid layer below, even if shSIZE is set to 0; however you can disable the dropshadow altogether, using shCOLOR.

Negative dropshadows are not possible - shSIZE cannot be less than 0. However you can configure the shadow to protrude in both directions, so that it completely surrounds each menu. This might be useful if you wanted a border around the whole menu but not between individual items, such as in the retrotech demo. You could also use it with low opacity to create an aura effect. To use the dropshadow like this, define shSIZE as though it were a string, eg:

    var shSIZE = 3;     will produce a dropshadow, but
    var shSIZE = "3";   will produce an enclosing border
shCOLOR// menu drop shadow color

specify the dropshadow color, as a hex color value, color name or as a GIF or JPEG image. Disable this layer by defining shCOLOR = ""

shOPACITY// menu drop shadow opacity (not ie4,ns4 or opera)

specify an opacity filter to make the dropshadow translucent. This is not supported explorer 4, netscape 4 or opera, or in mozilla builds earlier than 0.9

keepSubLIT// keep submenu rollover color when browsing child menu

the choices are true or false. If true then srCOLOR will remain when your mouse leaves the menu and browses the child menu, and will rollout when the menus close

chvOFFSET// shift the child menus vertically

by default, each child menu will be immediately next to its parent submenu cell and aligned with the top border (not overlapping). Use this value to shift the child menus down (+) or up (-) the specified number of pixels. You can also offset each child menu individually, using the child menu properties

chhOFFSET// shift the child menus horizontally

use this value to shift the child menus right (+) or left (-) the specified number of pixels. Child menus which are aligned to their right edge will be offset in the opposite direction. You can also offset each child menu individually, using the child menu properties

closeTIMER// menu closing delay time

specify the time delay in milliseconds from when your mouse leaves the menus to when they close. You can set this to a very high value and you'll get effective menu persistence; or set it to 0 for an instant reaction. I suggest a short timer, enough to allow for less than precise navigation - i've used 330 milliseconds on this page. At all settings, the menus can be closed by clicking anywhere in the page body.

Be aware that when a menu is open, the page is temporarily covered with an event-handling layer, with the side-effect that events from other elements on your page will not fire while the menus are still open.

cellCLICK// links activate on TD click

the choices are true or false. If true then links will be activated simply by clicking on the containing cell; if false then the containing cells are inert and only the links themselves are active.

aCURSOR// cursor for active links (not ns4 or opera)

specify the cursor to be used for active links.

Browsers differ in which css values they accept to specify a link cursor - the one that usually looks like a hand. ie6 recognises either "pointer" or "hand", to support the w3c standard "pointer", as well as the ie5 proprietary "hand". ie5 only recognises "hand", while mozilla only recognises "pointer". This script recognises either, and converts as necessary.

For ns4 and opera this value makes no difference, because they don't support cursor styles at all; containing cells have a default cursor and active-links a hand cursor. It would be possible to simulate a hand/default choice using superimposed layers, but the extra layers would slow down the script.

altDISPLAY// where to display alt text

If you've defined alt text as part of your link definitions, you can use this variable to determine how the text is displayed. The options are:

  • "title" - display the text as a title attribute (tooltip) which is activated when you mouseover the containing cell. This doesn't work in Netscape 4, which doesn't support the title attribute. Simulating tooltips with layers seemed rather OTT to me ...

    In Opera the tooltip is written into the status bar at the same time, which is hard-coded behaviour for alt and title attributes; in the windows version the tooltip is cancelled when you hover over the link text

  • "status" - display the text in the status bar; this is functional in all browsers and is triggered when you mouseover the containing cell. In Opera 5 the status message will be replaced by the url when you hover over the link text

  • "" - disable alt text
allowRESIZE// allow resize/reload

the choices are true, false or mu. If true then whenever you resize the browser window the page will be reloaded. This defaults to true, because resizing means the internal width of the browser window will have changed, and this is an important figure in a number of options:

  • if you have stretchMENU or showBORDERS set to true, this value determines the total width of the navbar.
  • if you have menuALIGN set to "right" or "center", this value is used to calculate the position of the nav.

So, accepting that you will lose the ability to reposition or resize the menu when the window size changes, you can disable resize/reload by setting allowRESIZE=false;

However in netscape 4, if you resize a window containing absolutely positioned layers, they all screw up horribly, making a mess of the navbar. This is another reason why the reload is used, because it protects against this "bug". If you do decide to disable the refresh, I strongly advise that you nevertheless allow it for netscape 4. You can specify that only ns4 reloads onresize by setting allowRESIZE=mu;

There are ways of designing a page such that a reload/resize trap is never necessary, other than for netscape 4. If you find reloading a distraction, then it's worth reading this page

redGRID// show a red grid

gridWIDTH// override grid width

gridHEIGHT// override grid height

documentWIDTH// override document width

These variables allow you to take control of the menu's event-handling layer, and the returned document width. It's quite complicated to explain why this is useful, so I've devoted a whole page to it - Controlling the event-handling layer

hideSELECT// auto-hide select boxes when menus open (ie5+ only)

the choices are true or false. If true then every select element on the page will be made invisible when a menu is open, and visible again when all are closed. This option requires that select elements have an explicit visibility property, which the script takes care of itself; therefore if your page already contains invisibile select elements, their invisibility will be overridden.

allowForSCALING// allow for text scaling in mozilla 5

the choices are true or false. If true, then the submenus and child menus will expand with large text in mozilla 5.

Unfortunately, this feature exposes another of its rendering bugs, whereby if a block-level element has its width specified as width:auto;min-width: n px and it also has a background-image, then that image will not fully tile; it only partially covers the available area. This happens whether or not the element is at its minimum width, which means the same problem is seen even if the text is normal size.

It also sometimes happens with background colors, although in a much stranger way; it appears to offset or increase the background area when its color is dynamically changed, but i'm not sure really; it's very weird.

Anyway, if you set this variable to true and then test your menus in mozilla 5, you will be able to see whether this is happening; it will be very obvious because the rollovers either don't completely fill their cells, or overlap. If all is cool, then all is cool; otherwise it's better to have allowForSCALING=false, which you should also do for safety if you don't test in mozilla at all.

With allowForSCALING disabled the menu containers will still expand, but the internal cells will not.

Menu and link definitions

The menus and links are created using array building functions, and there are five of them for each link/menu/children set:

The main links

"http://www.domain.com/"

the link URL. If your site is split across multiple folders, I recommend using absolute links, or links which are relative to the base directory. If you define it as "" then the link name will not be an active link, but can still have a submenu associated with it

"Home"

the link name. I should think you'll mostly want to use text links, but in fact they can also contain HTML. See advanced customising for more information. If you don't specify a name then it will default to a single non-breaking space

100

the width of the containing cell, in pixels. If any of the menu links are too long for their container, then the text will wrap and the cells will go out of sync with the nav stretching. To get proper alignment you need to tell the script where the line breaks should be, and you do this by using <br> tags in the link text. If you're using free alignment then only the applicable cell will increase in height, otherwise the whole navbar will increase to accomodate the tallest link.

"left"

text alignment, the options are "left", "right" or "center". If you define this as "" it will default to "left"

"_top"

the target for that link. The options are "_self", "_parent", "_top", "_blank" or "framename" where framename is the name of the target frame. The targetting mechanism supports sibling frames in a standard frameset, and iframes. If you define it as "" it will default to "_self"

"Home page"

the alt text for that link. The text can be a tooltip or a status bar message, which is defined using altDISPLAY. If you set this to "" then the link will have no alt text

0

top and left position. If you're using a standard horizontal navbar then these two values are ignored. However if you've set menuALIGN="free" to break the nav into component cells, then they determine the top and left position of each link cell, relative to absTOP and absLEFT. If you use relative positioning for cells in free alignment, then whatever you define here is overriden by each successive free-anchor image.

0

"h"

specify a key trigger for the attached submenu, if there is one. Available in Internet Explorer 5 and 6 only, this feature allows you to navigate using the keyboard. For more information, see the accessibility guide. If you don't intend to use this feature, you can define it as ""

If you don't want a submenu then that's all there is to it, you can move onto the next main link item. But if you do then you need to define these two arrays:

The submenu properties:

250

the width of the submenu, in pixels. If any of the submenu links are too long for the width of the menu, then the text will wrap and the links will go out of sync with the background. To get proper alignment you need to tell the script where the line breaks should be, and you do this by using <br> tags in the link text

"right"

which of its edges the submenu is aligned against, and therefore which direction it opens in, the options are "left" or "right". If you define it as "" it will default to "left"

"center"

text alignment, the options are "left", "right" or "center". If you define it as "" it will default to "left"

7

vertical offset, down (+) or up (-) in addition to vOFFSET, in pixels

-4

horizontal offset, left (+) or right (-) in addition to hOFFSET, in pixels. Menus which open from the right will be offset in the opposite direction

"filter:alpha(opacity=75)"

add a filter or transition effect to the menu (ie5.5/6 only)

The submenu links:

"/index.html"

the link URL. If your site is split across multiple folders, I recommend using absolute links, or links which are relative to the base directory.

If you define a link as "" then it will not be an active link, but can still have a child menu associated with it. If you define a link as "~" (tilda) it will additionally disable the rollover for that link cell, allowing you to build gaps or decorative elements into the menu.

"Home page"

the link text. Submenu links can also contain HTML; see advanced customising for more information. If you don't specify a name then it will default to a single non-breaking space

"_top"

the target for that link. The options are "_self", "_parent", "_top", "_blank" or "framename" where framename is the name of the target frame. The targetting mechanism supports sibling frames in a standard frameset, and iframes. If you define it as "" it will default to "_self"

"Go to my home page"

the alt text for that link. The text can be a tooltip or a status bar message, which is defined using altDISPLAY. If you set this to "" then the link will have no alt text

Keep repeating that last function to add more links to the menu.

If you want to have a child menu attached to a particular link, there are two more arrays you need to build after the submenu link definition:

The child menu properties:

142

the width of the child menu, in pixels. If any of the child menu links are too long for the width of the menu, then the text will wrap and the links will go out of sync with the background. To get proper alignment you need to tell the script where the line breaks should be, and you do this by using <br> tags in the link text

"left"

which of its edges the child menu is aligned against, and therefore which direction it opens in, the options are "left" or "right". If you define it as "" it will default to "left"

"left"

text alignment, the options are "left", "right" or "center". If you define it as "" it will default to "left"

-5

vertical offset, down (+) or up (-) in addition to chvOFFSET, in pixels

4

horizontal offset, left (+) or right (-) in addition to chhOFFSET, in pixels. Child menus which are aligned to their right edge will be offset in the opposite direction

"filter:alpha(opacity=75)"

add a filter or transition effect to the menu (ie5.5/6 only)

The child menu links:

"/trance.shtml"

the link URL. If your site is split across multiple folders, I recommend using absolute links, or links which are relative to the base directory.

If you define a link as "" then it will not be an active link. If you define a link as "~" (tilda) it will additionally disable the rollover for that link cell, allowing you to build gaps or decorative elements into the menu.

"Trance & Techno"

the link text. Child menu links can also contain HTML; see advanced customising for more information. If you don't specify a name then it will default to a single non-breaking space

"_top"

the target for that link. The options are "_self", "_parent", "_top", "_blank" or "framename" where framename is the name of the target frame. The targetting mechanism supports sibling frames in a standard frameset, and iframes. If you define it as "" it will default to "_self"

"Killer tunes"

the alt text for that link. The text can be a tooltip or a status bar message, which is defined using altDISPLAY. If you set this to "" then the link will have no alt text

Keep repeating the last function to add more links to the child menu.

Then keep repeating those five functions to add more main items, menus and child menus to the navbar. Make sure you define the arrays in the correct order - they must always follow this pattern:

addMainItem

etc ...

There is no limit to how many links and menus you can have, but it makes sense to keep the whole navbar visible and all the menus above the fold at 800 x 600 - this gives you roughly 750 x 450 to play with. For a horizontal dropdown You can work out the total width like this:

Or use a fixed documentWIDTH and visibile redGRID to compare against.


Hooray!

And there you go - that's all there is to it

Now you may want to go futher and conditionalise the link definitions, make an image-based navbar, or code in new behaviours such as customised windows or transition effects. The modular design of this script makes new features easy to integrate. Check out advanced customising to find out more.